<template>
  <div class="c-shopInfo">
    <div class="shopInfo-title">
      <i class="el-icon-s-order"></i>
      <span>店铺基本信息</span>
    </div>
    <div class="shopInfo-content">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        label-position="right"
        class="demo-ruleForm"
      >
        <el-row :gutter="20">
          <el-col :span="10">
            <div class="shopInfo-left">
              <el-form-item label="活动名称" prop="name">
                <el-input v-model="ruleForm.name"></el-input>
              </el-form-item>
              <el-form-item label="联系电话" prop="phone">
                <el-input v-model="ruleForm.phone"></el-input>
              </el-form-item>
              <el-form-item label="经营品类" prop="region">
                <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
                  <el-option label="区域一" value="shanghai"></el-option>
                  <el-option label="区域二" value="beijing"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="详细地址">
                <el-cascader
                  placeholder="省-市-区"
                  v-model="ruleForm.selectedOptions"
                  :options="ruleForm.options"
                  @change="handleChange"
                  :separator="' '"
                ></el-cascader>
              </el-form-item>
              <el-form-item label="选择商圈" prop="region">
                <el-select v-model="ruleForm.region" placeholder="请选择商圈">
                  <el-option label="区域一" value="shanghai"></el-option>
                  <el-option label="区域二" value="beijing"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="店铺简介">
                <el-input type="textarea" v-model="ruleForm.desc" maxlength="50" show-word-limit></el-input>
              </el-form-item>
              <el-form-item label="营业日期">
                <el-input
                  type="text"
                  v-model="ruleForm.date"
                  placeholder="星期一到星期日"
                  suffix-icon="el-icon-date"
                ></el-input>
              </el-form-item>
              <el-form-item label="营业时段">
                <el-input
                  type="text"
                  v-model="ruleForm.time"
                  placeholder="10:00～22:00"
                  suffix-icon="el-icon-alarm-clock"
                ></el-input>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="shopInfo-center">
              <div class="shopInfo-line"></div>
              <div class="shopInfo-lump"></div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="shopInfo-right">
              <el-form-item label="门头照" prop="picLogo">
                <el-upload
                  action="https://jsonplaceholder.typicode.com/posts/"
                  list-type="picture-card"
                  :on-preview="handlePictureCardPreview"
                  :on-remove="handleRemove"
                >
                  <i class="el-icon-plus"></i>
                </el-upload>
                <el-dialog :visible.sync="dialogVisible">
                  <img width="100%" :src="dialogImageUrl" alt>
                </el-dialog>
              </el-form-item>
              <el-form-item label="Logo" prop="logo">
                <el-upload
                  action="https://jsonplaceholder.typicode.com/posts/"
                  list-type="picture-card"
                  :on-preview="handlePictureCardPreview"
                  :on-remove="handleRemove"
                >
                  <i class="el-icon-plus"></i>
                </el-upload>
                <el-dialog :visible.sync="dialogVisible">
                  <img width="100%" :src="dialogImageUrl" alt>
                </el-dialog>
              </el-form-item>
              <el-form-item label="店铺图片" prop="shopPic">
                <el-upload
                  action="https://jsonplaceholder.typicode.com/posts/"
                  list-type="picture-card"
                  :on-preview="handlePictureCardPreview"
                  :on-remove="handleRemove"
                >
                  <i class="el-icon-plus"></i>
                </el-upload>
                <el-dialog :visible.sync="dialogVisible">
                  <img width="100%" :src="dialogImageUrl" alt>
                </el-dialog>
              </el-form-item>
              <el-form-item align="right">
                <el-button type="primary">保存</el-button>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import options from "@/assets/js/country-data.js";

export default {
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false,
      ruleForm: {
        name: "",
        phone: "",
        //存放默认值
        selectedOptions: [],
        //存放城市数据
        options: options,
        date: "",
        time: ""
      },
      rules: {
        name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        phone: [{ required: true, message: "请输入电话号码", trigger: "blur" }],
        picLogo: [{ required: true, message: "请上传图片", trigger: "blur" }],
        logo: [{ required: true, message: "请上传图片", trigger: "blur" }],
        shopPic: [{ required: true, message: "请上传图片", trigger: "blur" }]
      }
    };
  },
  methods: {
    //选择城市
    handleChange(value) {
      console.log(value);
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 上传图片
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    }
  }
};
</script>

<style scoped lang="scss">
.c-shopInfo {
  border: 1px solid #e8e8e8;
  .shopInfo-title {
    width: 100%;
    height: 60px;
    line-height: 60px;
    text-align: center;
    background: #3881f8;
    color: #fff;
    font-size: 22px;
    span{
      margin-left: 10px;
    }
  }
  .shopInfo-content {
    margin: 40px 0;
    .shopInfo-left {
      .el-cascader,
      .el-select {
        width: 100%;
      }
    }
    .shopInfo-center {
      position: relative;
      width: 10px;
      height: 480px;
      margin: 0 auto;
      .shopInfo-line {
        position: absolute;
        left: 5px;
        width: 1px;
        height: 100%;
        background: #dcdcdc;
      }
      .shopInfo-lump {
        position: absolute;
        width: 10px;
        height: 80px;
        background: #ffd565;
        left: 0;
        top: 50%;
        margin-top: -40px;
        z-index: 9;
      }
    }
    .shopInfo-right {
      margin-left: -30px;
    }
  }
}
</style>

<style>
.el-textarea .el-input__count {
  line-height: 20px;
}
</style>
